package com.cnvai.cms.web.controller;

import java.math.BigDecimal;
import java.util.List;

import javax.inject.Inject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cnvai.cms.business.api.CompanyService;
import com.cnvai.cms.business.api.DepartmentService;
import com.cnvai.cms.business.api.EmployeesService;
import com.cnvai.cms.javabean.model.Bmbmb;
import com.cnvai.cms.javabean.model.Dwjbxxb;
import com.cnvai.cms.javabean.model.Ygjbxx;
import com.cnvai.cms.javabean.vo.JqueryTree;
import com.cnvai.cms.web.vo.Datagrid;

@Controller
@RequestMapping("/organization")
public class OrganizationController {

	@Inject
	private CompanyService companyService;

	@Inject
	private DepartmentService departmentService;

	@Inject
	private EmployeesService employeesService;

	public CompanyService getCompanyService() {
		return companyService;
	}

	public void setCompanyService(CompanyService companyService) {
		this.companyService = companyService;
	}

	public DepartmentService getDepartmentService() {
		return departmentService;
	}

	public void setDepartmentService(DepartmentService departmentService) {
		this.departmentService = departmentService;
	}

	public EmployeesService getEmployeesService() {
		return employeesService;
	}

	public void setEmployeesService(EmployeesService employeesService) {
		this.employeesService = employeesService;
	}

	@RequestMapping("/companyHome")
	public String company() {
		return "organization/company";
	}

	@RequestMapping("/companyAdd")
	public String companyAdd() {
		return "organization/companyAdd";
	}

	@RequestMapping("/saveCompany")
	public String saveCompany(Dwjbxxb jbxx) {
		String result = "success";
		try {
			getCompanyService().saveCompany(jbxx);
		} catch (Exception e) {
			result = "fail";
		}
		return result;
	}

	@RequestMapping("/getCompanList")
	@ResponseBody
	public Datagrid getCompanList() {
		Datagrid data = new Datagrid();
		List<Dwjbxxb> list = getCompanyService().getCompanyListALL();
		data.setTotal(list.size());
		data.setRows(list);
		return data;
	}

	@RequestMapping("/loadCompanyTree")
	@ResponseBody
	public List<JqueryTree> loadCompanyTree(BigDecimal fbossid) {
		return getCompanyService().loadCompanyTree(fbossid);
	}

	@RequestMapping("/deleteCompany")
	@ResponseBody
	public String deleteCompany(String ids) {
		String result = "success";
		try {
			getCompanyService().deleteCompany(ids);
		} catch (Exception e) {
			result = "fail";
		}
		return result;
	}

	@RequestMapping("/departmentHome")
	public String department() {
		return "organization/department";
	}

	@RequestMapping("/departmentAdd")
	public String departmentAdd() {
		return "organization/departmentAdd";
	}

	@RequestMapping("/saveDeparment")
	public String saveDeparment(Bmbmb bmb) {
		String result = "success";
		try {
			getDepartmentService().saveDepartment(bmb);
		} catch (Exception e) {
			result = "fail";
		}
		return result;
	}

	@RequestMapping("/getDepartmentList")
	@ResponseBody
	public Datagrid getDepartmentList(BigDecimal bossid, BigDecimal fjdid) {
		Datagrid data = new Datagrid();
		List<Bmbmb> list = getDepartmentService().getDepartmentList(bossid, fjdid);
		data.setTotal(list.size());
		data.setRows(list);
		return data;
	}

	@RequestMapping("/loadDepartmentTree")
	@ResponseBody
	public List<JqueryTree> loadDepartmentTree(BigDecimal bossid, BigDecimal fjdid) {
		return getDepartmentService().loadDepartmentTree(bossid, fjdid);
	}

	@RequestMapping("/deleteDepartment")
	@ResponseBody
	public String deleteDepartment(String ids) {
		String result = "success";
		try {
			getDepartmentService().deleteDepartment(ids);
		} catch (Exception e) {
			result = "fail";
		}
		return result;
	}

	@RequestMapping("/employeesHome")
	public String employees() {
		return "organization/employees";
	}

	@RequestMapping("/employeesAdd")
	public String employeesAdd() {
		return "organization/employeesAdd";
	}

	@RequestMapping("/saveEmployees")
	public String saveEmployees(Ygjbxx jbxx) {
		String result = "success";
		try {
			getEmployeesService().saveEmployees(jbxx);
		} catch (Exception e) {
			result = "fail";
		}
		return result;
	}

	@RequestMapping("/getEmployeesList")
	@ResponseBody
	public Datagrid getEmployeesList() {
		Datagrid data = new Datagrid();
		List<Ygjbxx> list = getEmployeesService().getEmployeesListALL();
		data.setTotal(list.size());
		data.setRows(list);
		return data;
	}

	@RequestMapping("/delteEmployees")
	@ResponseBody
	public String delteEmployees(String ids) {
		String result = "success";
		try {
			getEmployeesService().deleteEmployees(ids);
		} catch (Exception e) {
			result = "fail";
		}
		return result;
	}

}
